from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class AddressBookPackage:
    def __init__(self, driver):
        self.driver = driver

    def add_user(self):
        # WebDriverWait(self.driver, 20).until(
        #     EC.presence_of_element_located((By.XPATH, "//*[@class='qui_btn ww_btn js_add_member']")))
        self.driver.find_elements(By.XPATH, "//*[@class='qui_btn ww_btn js_add_member']")[-1].click() # 注意[-1]的表达方式
        WebDriverWait(self.driver, 20).until
            EC.presence_of_element_located((By.XPATH, "//*[@id='username']")))  # 注意这里的双括号
        self.driver.find_element(By.XPATH, "//*[@id='username']").send_keys("成员01")
        self.driver.find_element(By.XPATH, "//*[@id='memberAdd_english_name']").send_keys("别名01")
        self.driver.find_element(By.XPATH, "//*[@id='memberAdd_acctid']").send_keys("账号01")
        self.driver.find_element(By.XPATH, "//*[@class='qui_inputText ww_inputText ww_telInput_mainNumber']").send_keys(
            "13578541245")
        # 点击保存
        self.driver.find_element(By.XPATH, "//*[@class='qui_btn ww_btn js_btn_save']").click()